% Remember to use the lgrind style

\Head{}
\File{./java/MapComponent.java}{2006}{4}{27}{19:09}{17041}
\L{\LB{\C{}/*}}
\L{\LB{_*_MapComponent.java}}
\L{\LB{_*}}
\L{\LB{_*_Created_on_January_8,_2006,_1:50_PM}}
\L{\LB{_*/\CE{}}}
\L{\LB{\C{}//_\<applet_code={'}Main{'}_width={'}200{'}_height={'}50{'}\>\</applet\>\CE{}}}
\L{\LB{}}
\L{\LB{\K{package}_\V{project01};}}
\L{\LB{}}
\L{\LB{\K{import}_\V{javax}.\V{swing}.*;}}
\L{\LB{\K{import}_\V{java}.\V{awt}.*;}}
\L{\LB{\K{import}_\V{java}.\V{util}.*;}}
\L{\LB{\K{import}_\V{com}.\V{bruceeckel}.\V{swing}.*;}}
\L{\LB{\K{import}_\V{java}.\V{lang}.*;}\Tab{24}{\C{}//_Runtime\CE{}}}
\L{\LB{\K{import}_\V{java}.\V{io}.*;}\Tab{24}{\C{}//_IO_Streams\CE{}}}
\L{\LB{\K{import}_\V{java}.\V{net}.\V{URL};}}
\L{\LB{\C{}//import_java.beans.*;}\Tab{26}{//_XMLEncoder/Decoder\CE{}}}
\L{\LB{\C{}//import_org.devlib.schmidt.imageinfo.*;}\Tab{48}{//_for_getting_image_dpi\CE{}}}
\L{\LB{\K{import}_\V{com}.\V{sun}.\V{image}.\V{codec}.\V{jpeg}.*;}\Tab{48}{\C{}//_for_getting_image_dpi\CE{}}}
\L{\LB{}}
\L{\LB{\C{}/**}}
\L{\LB{_*_Manages_and_draws_nodes_and_edges.}}
\L{\LB{_*_\<p\>}}
\L{\LB{_*_Note:_Original_name_was_\3InteractiveMapComponent\3_so_\3imc\3_is_found}}
\L{\LB{_*_throughout_src_when_using_it}}
\L{\LB{_*}}
\L{\LB{_*_\CE{}\V{author}_\V{Ian}_\V{Melnick}}}
\L{\LB{\C{}*/\CE{}}}
\L{\LB{\K{public}_\K{class}_\V{MapComponent}_\K{extends}_\V{JComponent}_\{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}//_class_vars---current_coords_for_drawing,_etc_etc.\CE{}}}
\L{\LB{}\Tab{4}{\K{public}_\V{NodeManager}}\Tab{28}{\V{nm};}}
\L{\LB{}\Tab{4}{\K{public}_\V{MapManager}}\Tab{28}{\V{mm};}}
\L{\LB{}\Tab{4}{\V{String}}\Tab{28}{\V{map};}\Tab{44}{\C{}//_map_name_to_use/load\CE{}}}
\L{\LB{}\Tab{4}{\V{URL}}\Tab{28}{\V{mapPath};}\Tab{44}{\C{}//_location_of_image\CE{}}}
\L{\LB{}\Tab{4}{\V{ImageIcon}}\Tab{28}{\V{mapImage};}\Tab{44}{\C{}//_stores_the_image_data\CE{}}}
\L{\LB{}\Tab{4}{\C{}//JPEGImageDecoder}\Tab{30}{mapImageInfo;}\Tab{46}{//_contains_image_resolution_in_dpi\CE{}}}
\L{\LB{}\Tab{4}{\V{Point}}\Tab{28}{\V{mapCoords};}\Tab{44}{\C{}//_current_image_coordinates_relative_to_top-left_corner_of_screen\CE{}}}
\L{\LB{}\Tab{4}{\V{Dimension}}\Tab{28}{\V{mapSize};}\Tab{44}{\C{}//_loaded_map_image_dimensions\CE{}}}
\L{\LB{}\Tab{4}{\V{LinkedList}\<\V{NodeItem}\>}\Tab{28}{\V{nodes};}\Tab{44}{\C{}//_array_of_nodes\CE{}}}
\L{\LB{}\Tab{4}{\K{int}}\Tab{28}{\V{nodeSize};}\Tab{44}{\C{}//_visible_node_diameter\CE{}}}
\L{\LB{}\Tab{4}{\K{int}}\Tab{28}{\V{nodeId};}\Tab{44}{\C{}//_node_counter_for_setting_ID_numbers\CE{}}}
\L{\LB{}\Tab{4}{\K{public}_\K{int}}\Tab{28}{\V{edgeId};}\Tab{44}{\C{}//_edge_counter_for_setting_ID_numbers\CE{}}}
\L{\LB{}\Tab{4}{\V{Runtime}}\Tab{28}{\V{r};}\Tab{44}{\C{}//_gets_info_such_as_memory_use\CE{}}}
\L{\LB{}\Tab{4}{\V{String}}\Tab{28}{\V{dataDir};}\Tab{44}{\C{}//_directory_to_save/load_data_to/from\CE{}}}
\L{\LB{}\Tab{4}{\K{boolean}}\Tab{28}{\V{drawInvis};}\Tab{44}{\C{}//_draw_invisible_nodes?\CE{}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{11}{}}
\index{MapComponent}\Proc{MapComponent}\L{\LB{}\Tab{4}{\K{public}_\V{MapComponent}(\V{String}_\V{map})_\{}}
\L{\LB{}\Tab{8}{\V{nm}}\Tab{20}{=_\K{new}_\V{NodeManager}();}}
\L{\LB{}\Tab{8}{\V{mm}}\Tab{20}{=_\K{new}_\V{MapManager}();}}
\L{\LB{}\Tab{8}{\V{r}}\Tab{20}{=_\V{Runtime}.\V{getRuntime}();}}
\L{\LB{}\Tab{8}{\K{this}.\V{map}}\Tab{20}{=_\V{map};}}
\L{\LB{}\Tab{8}{\V{nodeSize}}\Tab{20}{=_\N{20};}}
\L{\LB{}\Tab{8}{\V{drawInvis}}\Tab{20}{=_\K{false};}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{mapPath}}\Tab{20}{=_\V{MapComponent}.\K{class}.\V{getResource}(\S{}\3images/map\_\3\SE{}+\V{map}+\S{}\3.jpg\3\SE{});}\Tab{87}{\C{}//_http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html\CE{}}}
\L{\LB{}\Tab{8}{\K{if}(\V{mapPath}==\K{null})_\{}}
\L{\LB{}\Tab{12}{\V{JOptionPane}.\V{showMessageDialog}(\K{null},_\S{}\3Requested_map_not_found\3\SE{},_\S{}\3Error\3\SE{},_\V{JOptionPane}.\V{ERROR\_MESSAGE});}}
\L{\LB{}\Tab{12}{\V{System}.\V{exit}(\N{1});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\C{}//_System.getenv_requires_Java_1.5\CE{}}}
\L{\LB{}\Tab{8}{\K{if}(\V{System}.\V{getenv}(\S{}\3HOMEDRIVE\3\SE{})==\K{null})_\{}}
\L{\LB{}\Tab{12}{\V{dataDir}_=_\V{System}.\V{getenv}(\S{}\3HOME\3\SE{});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\K{else}_\{}}
\L{\LB{}\Tab{12}{\V{dataDir}_=_\V{System}.\V{getenv}(\S{}\3HOMEDRIVE\3\SE{})_+_\V{System}.\V{getenv}(\S{}\3HOMEPATH\3\SE{});}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\C{}//_initMap()\CE{}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{nodes}}\Tab{20}{=_\K{new}_\V{LinkedList}\<\V{NodeItem}\>();}}
\L{\LB{}\Tab{8}{\V{nodeId}}\Tab{20}{=_\N{0};}}
\L{\LB{}\Tab{8}{\V{edgeId}}\Tab{20}{=_\N{0};}}
\L{\LB{}\Tab{4}{\}}}
\index{initMap}\Proc{initMap}\L{\LB{}\Tab{4}{\K{public}_\K{void}_\V{initMap}(\K{boolean}_\V{drawInvisibles})_\{}}
\L{\LB{}\Tab{8}{\K{this}.\V{drawInvis}_=_\V{drawInvisibles};}}
\L{\LB{}\Tab{8}{\K{this}.\V{initMap}();}}
\L{\LB{}\Tab{4}{\}}}
\index{initMap}\Proc{initMap}\L{\LB{}\Tab{4}{\K{public}_\K{void}_\V{initMap}()_\{}}
\L{\LB{}\Tab{8}{\C{}//_Set_up_mapImageInfo\CE{}}}
\L{\LB{}\Tab{8}{\C{}/*try_\{}}
\L{\LB{}\Tab{12}{mapImageInfo_=_JPEGCodec.createJPEGDecoder(mapPath.openStream());}}
\L{\LB{}\Tab{8}{\}_catch_(IOException_err)_\{}}
\L{\LB{}\Tab{12}{System.err.println(\3MapComponent:_mapImageInfo:_\3_+_err);}}
\L{\LB{}\Tab{8}{\}*/\CE{}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\C{}//_Set_up_mapImage\CE{}}}
\L{\LB{}\Tab{8}{\V{mapImage}}\Tab{20}{=_\K{new}_\V{ImageIcon}(\V{mapPath});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{Errors}.\V{debug}(\S{}\3Image:_\3\SE{}_+_\V{mapImage});\C{}//_+_\3_(at:_\3_+_mapImageInfo.getJPEGDecodeParam()_+_\3)\3);\CE{}}}
\L{\LB{}\Tab{8}{\V{Errors}.\V{debug}(\S{}\3Mem_used:_\3\SE{}_+_\V{r}.\V{totalMemory}()_+_\S{}\3_bytes\3\SE{});}}
\L{\LB{}\Tab{8}{\V{Errors}.\V{debug}(\S{}\3Mem_max_:_\3\SE{}_+_\V{r}.\V{maxMemory}()_+}\Tab{54}{\S{}\3_bytes\3\SE{});}}
\L{\LB{}\Tab{8}{\V{Errors}.\V{debug}(\S{}\3Mem_free:_\3\SE{}_+_\V{r}.\V{freeMemory}()_+}\Tab{54}{\S{}\3_bytes\3\SE{});}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{mapCoords}}\Tab{20}{=_\K{new}_\V{Point}(\N{0},_\N{0});}\Tab{41}{\C{}//_-800,_-500\CE{}}}
\L{\LB{}\Tab{8}{\V{mapSize}}\Tab{20}{=_\K{new}_\V{Dimension}(\V{mapImage}.\V{getIconHeight}(),_\V{mapImage}.\V{getIconWidth}());}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{\C{}/*public_void_paintComponent(Graphics_g)_\{}}
\L{\LB{}\Tab{8}{//super.paintComponent(g);}}
\L{\LB{}\Tab{4}{\}*/\CE{}}}
\L{\LB{}\Tab{4}{\C{}//note:_paintComponent_used_to_be_in_separate_files_for_each\CE{}}}
\L{\LB{}\Tab{4}{\C{}//}\Tab{8}{primary_mode_window._Since_I_never_changed_it_for_any_of\CE{}}}
\L{\LB{}\Tab{4}{\C{}//}\Tab{8}{these_modes,_I{'}ve_merged_it_back_into_MapComponent.\,.\,.\CE{}}}
\index{paintComponent}\Proc{paintComponent}\L{\LB{}\Tab{4}{\K{public}_\K{void}_\V{paintComponent}(\V{Graphics}_\V{g})_\{}}
\L{\LB{}\Tab{8}{\K{super}.\V{paintComponent}(\V{g});}}
\L{\LB{}\Tab{8}{\V{mapImage}.\V{paintIcon}(\K{this},_\V{g},_(\K{int})\K{this}.\V{mapCoords}.\V{getX}(),_(\K{int})\K{this}.\V{mapCoords}.\V{getY}());}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{8}{\C{}//_loop_thru_nodes_and_draw_on_map_relative_to_current_image_position.\CE{}}}
\L{\LB{}\Tab{8}{\V{ListIterator}\<\V{NodeItem}\>_\V{nli},_\V{nlj};}}
\L{\LB{}\Tab{8}{\V{NodeItem}_\V{tn},_\V{un};}}
\L{\LB{}\Tab{8}{\V{EdgeItem}_\V{ec};}}
\L{\LB{}\Tab{8}{\V{Point}_\V{tp},_\V{up};}}
\L{\LB{}\Tab{8}{\V{Point}_\V{minCorner}_=_\V{mm}.\V{mapMinCorner}();}}
\L{\LB{}\Tab{8}{\V{Point}_\V{maxCorner}_=_\V{mm}.\V{mapMaxCorner}();}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{8}{\V{nli}_=_\K{this}.\V{nodes}.\V{listIterator}();_\C{}//_For_drawing_each_node\CE{}}}
\L{\LB{}\Tab{8}{\K{while}(\V{nli}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{12}{\V{tn}_=_\V{nli}.\V{next}();}}
\L{\LB{}}
\L{\LB{}\Tab{12}{\C{}//_Draw/print_node_if_it{'}s_within_current_shown_coordinates\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_1._Get_node_map_position\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_2._Determine_if_it{'}s_currently_visible:\CE{}}}
\L{\LB{}\Tab{12}{\C{}//}\Tab{18}{a._Get_component_size_//_this.getWidth(),_this.getHeight();\CE{}}}
\L{\LB{}\Tab{12}{\C{}//}\Tab{18}{b._Based_on_origin_coordinates_and_window_size,_are_these_coords_currently_visible?\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_3._Draw_oval_around_point\CE{}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\C{}//_Max_corner_is_current_map_coordinate\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_at_origin_(this.getCoordinates())_+_window_size_(this.getWidth(),_this.getHeight()).\CE{}}}
\L{\LB{}\Tab{12}{\V{tp}_=_\V{mm}.\V{positiveMapCoords}(\V{tn}.\V{location}());}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\C{}//_If_the_current_node_is_in_between_the_1st_corner_and_the_max_corner_then_it_should_be_shown,\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_along_with_its_edges_(next_block)\CE{}}}
\L{\LB{}\Tab{12}{\K{if}(_(\V{tp}.\V{getX}()_\<=_\V{maxCorner}.\V{getX}()_\&\&_\V{tp}.\V{getX}()_\>_\V{minCorner}.\V{getX}())_\&\&_}}
\L{\LB{}\Tab{16}{(\V{tp}.\V{getY}()_\<=_\V{maxCorner}.\V{getY}()_\&\&_\V{tp}.\V{getY}()_\>_\V{minCorner}.\V{getY}()))_\{}}
\L{\LB{}\Tab{16}{\C{}//_Draw_oval_relative_to_current_display_coords\CE{}}}
\L{\LB{}\Tab{16}{\C{}//g.fillOval(_((int)(tpos.getX()-minCorner.getX()-(nodeSize/2))),_((int)(tpos.getY()-minCorner.getY()-(nodeSize/2))),_nodeSize,_nodeSize_);\CE{}}}
\L{\LB{}\Tab{16}{\K{if}(\V{tn}.\V{selected}())}}
\L{\LB{}\Tab{20}{\V{drawNode}(\V{g},_\V{Color}.\V{red},_\V{tn});}}
\L{\LB{}\Tab{16}{\K{else}_\K{if}(!\V{tn}.\V{selected}())_\{}}
\L{\LB{}\Tab{20}{\K{if}(\V{tn}.\V{visibility}())}}
\L{\LB{}\Tab{24}{\V{drawNode}(\V{g},_\V{Color}.\V{green},_\V{tn});}}
\L{\LB{}\Tab{20}{\K{else}_\K{if}(!\V{tn}.\V{visibility}()_\&\&_\V{drawInvis})}}
\L{\LB{}\Tab{24}{\V{drawNode}(\V{g},_\V{Color}.\V{yellow},_\V{tn});}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{16}{\C{}//_Find_which_node(s)_are_related_to_this_one_and_draw_connecting_edges.\CE{}}}
\L{\LB{}\Tab{16}{\C{}//_IAN_DRAW_DISTANCE_FOR_LINE_HERE_.\,.\,._use_ec_=_sharedEdge(ns,_nd)\CE{}}}
\L{\LB{}\Tab{16}{\V{g}.\V{setColor}(\V{Color}.\V{black});}}
\L{\LB{}\Tab{16}{\V{tp}_=_\V{mm}.\V{mapCoordsToMouseCoords}(\V{tn}.\V{location}());}}
\L{\LB{}\Tab{16}{\V{nlj}_=_\V{nm}.\V{connectedNodes}(\V{tn}).\V{listIterator}();}}
\L{\LB{}\Tab{16}{\K{while}(\V{nlj}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{20}{\V{un}_=_\V{nlj}.\V{next}();}}
\L{\LB{}\Tab{20}{\V{up}_=_\V{mm}.\V{mapCoordsToMouseCoords}(\V{un}.\V{location}());}}
\L{\LB{}\Tab{20}{\V{ec}_=_\V{nm}.\V{sharedEdge}(\V{tn},_\V{un});}}
\L{\LB{}\Tab{20}{\V{g}.\V{drawLine}((\K{int})\V{tp}.\V{getX}(),_(\K{int})\V{tp}.\V{getY}(),_(\K{int})\V{up}.\V{getX}(),_(\K{int})\V{up}.\V{getY}());}}
\L{\LB{}\Tab{20}{\V{g}.\V{drawString}(\V{String}.\V{valueOf}(\V{ec}.\V{getDistance}()),_(\K{int})(_((\V{up}.\V{getX}()\-\V{tp}.\V{getX}())/\N{2})+\V{tp}.\V{getX}()_),_(\K{int})(((\V{up}.\V{getY}()\-\V{tp}.\V{getY}())/\N{2})+\V{tp}.\V{getY}())_);}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\index{drawNode}\Proc{drawNode}\L{\LB{}\Tab{4}{\K{void}_\V{drawNode}(\V{Graphics}_\V{g},_\V{Color}_\V{c},_\V{NodeItem}_\V{n})_\{}}
\L{\LB{}\Tab{8}{\V{g}.\V{setColor}(\V{c});}}
\L{\LB{}\Tab{8}{\V{Point}_\V{minCorner}_=_\V{mm}.\V{mapMinCorner}();}}
\L{\LB{}\Tab{8}{\V{Point}_\V{p}_=_\K{new}_\V{Point}(\V{mm}.\V{positiveMapCoords}(\V{n}.\V{location}()));}}
\L{\LB{}\Tab{8}{\V{g}.\V{fillOval}(_((\K{int})(\V{p}.\V{getX}()\-\V{minCorner}.\V{getX}()\-(\V{nodeSize}/\N{2}))),_((\K{int})(\V{p}.\V{getY}()\-\V{minCorner}.\V{getY}()\-(\V{nodeSize}/\N{2}))),_\V{nodeSize},_\V{nodeSize}_);}}
\L{\LB{}\Tab{8}{\V{g}.\V{setColor}(\V{Color}.\V{black});}}
\L{\LB{}\Tab{8}{\V{g}.\V{drawString}(\V{String}.\V{valueOf}(\V{n}.\V{id}()),_((\K{int})(\V{p}.\V{getX}()\-\V{minCorner}.\V{getX}()\-(\V{nodeSize}/\N{2}))),_((\K{int})(\V{p}.\V{getY}()\-\V{minCorner}.\V{getY}()\-(\V{nodeSize}/\N{2}))));}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\index{getCoordinates}\Proc{getCoordinates}\L{\LB{}\Tab{4}{\K{public}_\V{Point}_\V{getCoordinates}()_\{_\K{return}_\V{mapCoords};_\}}}
\index{getMapSize}\Proc{getMapSize}\L{\LB{}\Tab{4}{\K{public}_\V{Dimension}_\V{getMapSize}()_\{_\K{return}_\V{mapSize};}\Tab{54}{\}}}
\index{map}\Proc{map}\L{\LB{}\Tab{4}{\K{public}_\V{String}_\V{map}()}\Tab{34}{\{_\K{return}_\V{map};}\Tab{54}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}/**_Return_distance_in_Feet_between_two_nodes_*/\CE{}_}}
\index{calcDistance}\Proc{calcDistance}\L{\LB{}\Tab{4}{\K{public}_\K{int}_\V{calcDistance}(\V{NodeItem}_\V{a},_\V{NodeItem}_\V{b})_\{}}
\L{\LB{}\Tab{8}{\C{}//_TODO:_Both_sun_and_schmidt_libraries_don{'}t_extract_dpi,_but_windows_does!\CE{}}}
\L{\LB{}\Tab{8}{\C{}/*}}
\L{\LB{}\Tab{9}{*_Pixel_distance:}}
\L{\LB{}\Tab{9}{*}\Tab{13}{x_=_selNode.location().getX()_-_relNode.location().getX()}}
\L{\LB{}\Tab{9}{*}\Tab{13}{y_=_selNode.location().getY()_-_relNode.location().getY()}}
\L{\LB{}\Tab{9}{*_x.toPositive()}}
\L{\LB{}\Tab{9}{*_y.toPositive()}}
\L{\LB{}\Tab{9}{*_}}
\L{\LB{}\Tab{9}{*_Convert_pixels_to_inches,_to_feet:}}
\L{\LB{}\Tab{9}{*}\Tab{13}{feetwidth_=_(imc.getMapSize().getWidth()_/_getMapHorizDPI)_*_40}}
\L{\LB{}\Tab{9}{*}\Tab{13}{feetheight=_(imc.getMapSize().getHeight()_/_getMapVertDPI)_*_40}}
\L{\LB{}\Tab{9}{*/\CE{}}}
\L{\LB{}\Tab{8}{\V{Point}_\V{distancePx}_=_\V{mm}.\V{positiveMapCoords}(\V{mm}.\V{difference}(\V{a}.\V{location}(),_\V{b}.\V{location}()));}}
\L{\LB{}\Tab{8}{\K{int}_\V{mapHorizDPI}_=_\N{96};}\Tab{31}{\C{}//_TODO:_Needs_to_be_dynamic!\CE{}}}
\L{\LB{}\Tab{8}{\K{int}_\V{mapVertDPI}}\Tab{24}{=_\N{96};}}
\L{\LB{}\Tab{8}{\K{int}_\V{mapScale}}\Tab{24}{=_\N{40};}\Tab{31}{\C{}//_constant;_1\3_=_40{'}\CE{}}}
\L{\LB{}\Tab{8}{\K{int}_\V{feetWidth}}\Tab{24}{=_(\K{int})((\V{distancePx}.\V{getX}()_/_\V{mapHorizDPI})_*_\V{mapScale});}}
\L{\LB{}\Tab{8}{\K{int}_\V{feetHeight}}\Tab{24}{=_(\K{int})((\V{distancePx}.\V{getY}()_/_\V{mapVertDPI})_*_\V{mapScale});}}
\L{\LB{}\Tab{8}{\K{int}_\V{distanceFt}_=_(\K{int})\V{Math}.\V{sqrt}(\V{Math}.\V{pow}(\V{feetWidth},\N{2})+\V{Math}.\V{pow}(\V{feetHeight},\N{2}));}}
\L{\LB{}\Tab{8}{\K{return}_\V{distanceFt};}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\K{class}_\V{MapManager}_\{}}
\index{setOrigin}\Proc{setOrigin}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{setOrigin}(\V{Point}_\V{p})_\{}}
\L{\LB{}\Tab{12}{\C{}//_Check_that_we{'}re_still_on_the_map;_if_yes,_redraw\CE{}}}
\L{\LB{}\Tab{12}{\K{if}(_(\V{p}.\V{getY}()_\>_\-\V{mapSize}.\V{getHeight}()_\&\&_\V{p}.\V{getY}()_\<=_\N{0})_\&\&_}}
\L{\LB{}\Tab{16}{(\V{p}.\V{getX}()_\>_\-\V{mapSize}.\V{getWidth}()_\&\&_\V{p}.\V{getX}()_\<=_\N{0})_)_\{}}
\L{\LB{}\Tab{16}{\V{mapCoords}.\V{setLocation}(\V{p});}}
\L{\LB{}\Tab{16}{\V{repaint}();}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\index{centerAroundPoint}\Proc{centerAroundPoint}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{centerAroundPoint}(\V{Point}_\V{p})_\{}}
\L{\LB{}\Tab{12}{\V{p}_=_\V{positiveMapCoords}(\V{p});}}
\L{\LB{}\Tab{12}{\V{Point}_\V{newloc}_=_\K{new}_\V{Point}(_\-(\K{int})(\V{p}.\V{getX}()\-(\V{getWidth}()/\N{2})),_\-(\K{int})(\V{p}.\V{getY}()\-(\V{getHeight}()/\N{2}))_);}}
\L{\LB{}\Tab{12}{\V{setOrigin}(\V{newloc});}}
\L{\LB{}\Tab{8}{\}}}
\index{mouseCoordsToMapCoords}\Proc{mouseCoordsToMapCoords}\L{\LB{}\Tab{8}{\K{public}_\V{Point}_\V{mouseCoordsToMapCoords}(\V{Point}_\V{mouseCoords})_\{}}
\L{\LB{}\Tab{12}{\V{Point}_\V{minCorner}_=_\V{mapMinCorner}();}}
\L{\LB{}\Tab{12}{\C{}//Point_maxCorner_=_new_Point((int)(-this.getCoordinates().getX()+this.getWidth()),_(int)(-this.getCoordinates().getY()+this.getHeight()));\CE{}}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{Point}(_(\K{int})(\-\V{mouseCoords}.\V{getX}()\-\V{minCorner}.\V{getX}()),_(\K{int})(\-\V{mouseCoords}.\V{getY}()\-\V{minCorner}.\V{getY}())_);}}
\L{\LB{}\Tab{8}{\}}}
\index{mapCoordsToMouseCoords}\Proc{mapCoordsToMouseCoords}\L{\LB{}\Tab{8}{\K{public}_\V{Point}_\V{mapCoordsToMouseCoords}(\V{Point}_\V{mapCoords})_\{}}
\L{\LB{}\Tab{12}{\V{Point}_\V{minCorner}_=_\V{mapMinCorner}();}}
\L{\LB{}\Tab{12}{\V{Point}_\V{p}_=_\K{new}_\V{Point}(\V{positiveMapCoords}(\V{mapCoords}));}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{Point}(_(\K{int})(\V{p}.\V{getX}()\-\V{minCorner}.\V{getX}()),_(\K{int})(\V{p}.\V{getY}()\-\V{minCorner}.\V{getY}())_);}}
\L{\LB{}\Tab{8}{\}}}
\index{positiveMapCoords}\Proc{positiveMapCoords}\L{\LB{}\Tab{8}{\K{public}_\V{Point}_\V{positiveMapCoords}(\V{Point}_\V{negativeMapCoords})_\{}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{Point}(_(\K{int})(\V{Math}.\V{abs}(\V{negativeMapCoords}.\V{getX}())),_(\K{int})(\V{Math}.\V{abs}(\V{negativeMapCoords}.\V{getY}()))_);}}
\L{\LB{}\Tab{8}{\}}}
\index{mapMinCorner}\Proc{mapMinCorner}\L{\LB{}\Tab{8}{\K{public}_\V{Point}_\V{mapMinCorner}()_\{}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{Point}(\V{positiveMapCoords}(\V{getCoordinates}()));}}
\L{\LB{}\Tab{8}{\}}}
\index{mapMaxCorner}\Proc{mapMaxCorner}\L{\LB{}\Tab{8}{\K{public}_\V{Point}_\V{mapMaxCorner}()_\{}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{Point}((\K{int})(\-\V{getCoordinates}().\V{getX}()+\V{getWidth}()),_(\K{int})(\-\V{getCoordinates}().\V{getY}()+\V{getHeight}()));}}
\L{\LB{}\Tab{8}{\}}}
\index{offsetByMouse}\Proc{offsetByMouse}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{offsetByMouse}(\V{Point}_\V{mcp},_\V{Point}_\V{mrp})_\{}}
\L{\LB{}\Tab{12}{\V{Point}_\V{oc}_=_\K{new}_\V{Point}((\K{int})(\V{mrp}.\V{getX}()\-\V{mcp}.\V{getX}()),_(\K{int})(\V{mrp}.\V{getY}()\-\V{mcp}.\V{getY}()));}}
\L{\LB{}\Tab{12}{\V{Point}_\V{mc}_=_\K{new}_\V{Point}((\K{int})(\V{getCoordinates}().\V{getX}()+\V{oc}.\V{getX}()),_(\K{int})(\V{getCoordinates}().\V{getY}()+\V{oc}.\V{getY}()));}}
\L{\LB{}\Tab{12}{\V{setOrigin}(\V{mc});}}
\L{\LB{}\Tab{8}{\}}}
\index{difference}\Proc{difference}\L{\LB{}\Tab{8}{\K{public}_\V{Point}_\V{difference}(\V{Point}_\V{a},_\V{Point}_\V{b})_\{}}
\L{\LB{}\Tab{12}{\K{return}_\K{new}_\V{Point}((\K{int})(\V{a}.\V{getX}()\-\V{b}.\V{getX}()),(\K{int})(\V{a}.\V{getY}()\-\V{b}.\V{getY}()));}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\K{class}_\V{NodeManager}_\{}}
\index{addNode}\Proc{addNode}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{addNode}(\V{Point}_\V{p})_\{}}
\L{\LB{}\Tab{12}{\V{nodes}.\V{add}(\K{new}_\V{NodeItem}(\V{map},_\V{p},_++\V{nodeId}));}}
\L{\LB{}\Tab{12}{\V{repaint}();}}
\L{\LB{}\Tab{8}{\}}}
\index{delNode}\Proc{delNode}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{delNode}(\V{NodeItem}_\V{n})_\{}}
\L{\LB{}\Tab{12}{\V{NodeItem}_\V{c};}}
\L{\LB{}\Tab{12}{\V{EdgeItem}_\V{ei};}}
\L{\LB{}\Tab{12}{\V{ListIterator}\<\V{NodeItem}\>_\V{l}_=_\V{connectedNodes}(\V{n}).\V{listIterator}();}}
\L{\LB{}\Tab{12}{\V{Iterator}\<\V{EdgeItem}\>_\V{e};}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\K{while}(\V{l}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{16}{\V{c}_=_\V{l}.\V{next}();}}
\L{\LB{}\Tab{16}{\V{e}_=_\V{n}.\V{edges}().\V{iterator}();}}
\L{\LB{}\Tab{16}{\K{while}(\V{e}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{20}{\K{try}_\{}}
\L{\LB{}\Tab{24}{\V{ei}_=_\V{e}.\V{next}();}}
\L{\LB{}\Tab{24}{\K{if}(\V{c}.\V{hasEdge}(\V{ei}))}}
\L{\LB{}\Tab{28}{\V{c}.\V{delEdge}(\V{ei});}}
\L{\LB{}\Tab{20}{\}_\K{catch}_(\V{java}.\V{util}.\V{ConcurrentModificationException}_\V{er})_\{}}
\L{\LB{}\Tab{24}{\C{}//continue;\CE{}}}
\L{\LB{}\Tab{24}{\K{break};}}
\L{\LB{}\Tab{20}{\}}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\V{nodes}.\V{remove}(\V{n});}}
\L{\LB{}\Tab{12}{\V{repaint}();}}
\L{\LB{}\Tab{8}{\}}}
\index{getNodeAtCoords}\Proc{getNodeAtCoords}\L{\LB{}\Tab{8}{\K{public}_\V{NodeItem}_\V{getNodeAtCoords}(\V{Point}_\V{p})_\{}}
\L{\LB{}\Tab{12}{\V{p}_=_\V{mm}.\V{positiveMapCoords}(\V{mm}.\V{mouseCoordsToMapCoords}(\V{p}));}}
\L{\LB{}\Tab{12}{\V{ListIterator}\<\V{NodeItem}\>_\V{nli}_=_\V{nodes}.\V{listIterator}();}}
\L{\LB{}\Tab{12}{\V{Point}_\V{m};}}
\L{\LB{}\Tab{12}{\V{Object}_\V{tobj};}}
\L{\LB{}\Tab{12}{\V{NodeItem}_\V{tnod},_\V{rnod};}}
\L{\LB{}\Tab{12}{\V{rnod}_=_\K{null};}}
\L{\LB{}\Tab{12}{\K{while}(\V{nli}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{16}{\V{tnod}_=_\V{nli}.\V{next}();}}
\L{\LB{}\Tab{16}{\V{m}_=_\V{mm}.\V{positiveMapCoords}(\V{tnod}.\V{location}());}}
\L{\LB{}\Tab{16}{}}
\L{\LB{}\Tab{16}{\C{}//_If_p_is_within_tnod.location()_and_tnod.location()+nodeSize\CE{}}}
\L{\LB{}\Tab{16}{\C{}//_Make_sure_that_coords_being_compared_are_relative_to_screen,_like_passed_mouse_coords.\,.\,.\CE{}}}
\L{\LB{}\Tab{16}{\K{if}(_(\V{p}.\V{getX}()_\>=_\V{m}.\V{getX}()\-(\V{nodeSize})_\&\&_\V{p}.\V{getX}()_\<_\V{m}.\V{getX}()+(\V{nodeSize}))_\&\&}}
\L{\LB{}\Tab{20}{(\V{p}.\V{getY}()_\>=_\V{m}.\V{getY}()\-(\V{nodeSize})_\&\&_\V{p}.\V{getY}()_\<_\V{m}.\V{getY}()+(\V{nodeSize})))_\{}}
\L{\LB{}\Tab{20}{\V{rnod}_=_\V{tnod};}}
\L{\LB{}\Tab{20}{\K{break};}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\K{else}}}
\L{\LB{}\Tab{20}{\V{rnod}_=_\K{null};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{return}_\V{rnod};}}
\L{\LB{}\Tab{8}{\}}}
\index{getNodeById}\Proc{getNodeById}\L{\LB{}\Tab{8}{\K{public}_\V{NodeItem}_\V{getNodeById}(\K{int}_\V{nid})_\{}}
\L{\LB{}\Tab{12}{\V{NodeItem}_\V{n};}}
\L{\LB{}\Tab{12}{\V{ListIterator}\<\V{NodeItem}\>_\V{nli}_=_\V{nodes}.\V{listIterator}();}}
\L{\LB{}\Tab{12}{\K{while}(\V{nli}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{16}{\V{n}_=_\V{nli}.\V{next}();}}
\L{\LB{}\Tab{16}{\K{if}(\V{n}.\V{id}()==\V{nid})}}
\L{\LB{}\Tab{20}{\K{return}_\V{n};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{return}_\K{null};}}
\L{\LB{}\Tab{8}{\}}}
\index{connected}\Proc{connected}\L{\LB{}\Tab{8}{\K{public}_\K{boolean}_\V{connected}(\V{NodeItem}_\V{ns},_\V{NodeItem}_\V{nd})_\{}}
\L{\LB{}\Tab{12}{\K{if}(\V{connectedNodes}(\V{ns}).\V{contains}(\V{nd}))}}
\L{\LB{}\Tab{16}{\K{return}_\K{true};}}
\L{\LB{}\Tab{12}{\K{else}}}
\L{\LB{}\Tab{16}{\K{return}_\K{false};}}
\L{\LB{}\Tab{8}{\}}}
\index{connectedNodes}\Proc{connectedNodes}\L{\LB{}\Tab{8}{\K{public}_\V{LinkedList}\<\V{NodeItem}\>_\V{connectedNodes}(\V{NodeItem}_\V{n})_\{}}
\L{\LB{}\Tab{12}{\C{}/*_Return_a_LinkedList_of_nodes_connected_to_n_by_common_edges_*/\CE{}}}
\L{\LB{}\Tab{12}{\C{}//_NOTE:_Using_Generics,_no_longer_need_to_cast_objects_when_retrieving_from_List\CE{}}}
\L{\LB{}\Tab{12}{\V{ListIterator}\<\V{NodeItem}\>_\V{l};}}
\L{\LB{}\Tab{12}{\V{Iterator}\<\V{EdgeItem}\>_\V{e};}}
\L{\LB{}\Tab{12}{\V{NodeItem}_\V{c};}}
\L{\LB{}\Tab{12}{\V{LinkedList}\<\V{NodeItem}\>_\V{r}_=_\K{new}_\V{LinkedList}\<\V{NodeItem}\>();}}
\L{\LB{}\Tab{12}{\V{LinkedList}\<\V{NodeItem}\>_\V{tnodes}_=_\K{new}_\V{LinkedList}\<\V{NodeItem}\>(\V{nodes});}}
\L{\LB{}\Tab{12}{\V{tnodes}.\V{remove}(\V{n});}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\V{l}_=_\V{tnodes}.\V{listIterator}();_\C{}//_For_finding_which_node_contains_edge_relationship\CE{}}}
\L{\LB{}\Tab{12}{\K{while}(\V{l}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{16}{\V{c}_=_\V{l}.\V{next}();}}
\L{\LB{}\Tab{16}{\V{e}_=_\V{n}.\V{edges}().\V{iterator}();}}
\L{\LB{}\Tab{16}{\K{while}(\V{e}.\V{hasNext}())}}
\L{\LB{}\Tab{20}{\K{if}(\V{c}.\V{hasEdge}(_\V{e}.\V{next}()_))}}
\L{\LB{}\Tab{24}{\V{r}.\V{add}(\V{c});}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{}}
\L{\LB{}\Tab{12}{\K{return}_\V{r};}}
\L{\LB{}\Tab{8}{\}}}
\index{sharedEdge}\Proc{sharedEdge}\L{\LB{}\Tab{8}{\K{public}_\V{EdgeItem}_\V{sharedEdge}(\V{NodeItem}_\V{ns},_\V{NodeItem}_\V{nd})_\{}}
\L{\LB{}\Tab{12}{\V{EdgeItem}_\V{ei};}}
\L{\LB{}\Tab{12}{\V{Iterator}\<\V{EdgeItem}\>_\V{el}_=_\V{ns}.\V{edges}().\V{iterator}();}}
\L{\LB{}\Tab{12}{\K{while}(\V{el}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{16}{\V{ei}_=_\V{el}.\V{next}();}}
\L{\LB{}\Tab{16}{\K{try}_\{}}
\L{\LB{}\Tab{20}{\K{if}(\V{nd}.\V{hasEdge}(\V{ei}))}}
\L{\LB{}\Tab{24}{\K{return}_\V{ei};}}
\L{\LB{}\Tab{16}{\}_\K{catch}(\V{NullPointerException}_\V{err})_\{}}
\L{\LB{}\Tab{20}{\K{continue};}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{return}_\K{null};}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{8}{\C{}/**_Generates_a_list_of_visible_nodes_for_use_in_a_JComboBox_*/\CE{}}}
\index{nodeVector}\Proc{nodeVector}\L{\LB{}\Tab{8}{\K{public}_\V{Vector}\<\V{MapItem}\>_\V{nodeVector}()_\{}}
\L{\LB{}\Tab{12}{\V{Vector}\<\V{MapItem}\>_\V{nodeVector}_=_\K{new}_\V{Vector}\<\V{MapItem}\>();}}
\L{\LB{}\Tab{12}{\V{NodeItem}_\V{n};}}
\L{\LB{}\Tab{12}{\V{ListIterator}\<\V{NodeItem}\>_\V{nli}_=_\V{nodes}.\V{listIterator}();}}
\L{\LB{}\Tab{12}{\C{}//nodeVector.add(new_MapItem(-1,_map()));\CE{}}}
\L{\LB{}\Tab{12}{\K{while}(\V{nli}.\V{hasNext}())_\{}}
\L{\LB{}\Tab{16}{\V{n}_=_\V{nli}.\V{next}();}}
\L{\LB{}\Tab{16}{\K{if}(\V{n}.\V{visibility}())_\{}\Tab{40}{}}
\L{\LB{}\Tab{20}{\V{nodeVector}.\V{add}(\V{n});}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{return}_\V{nodeVector};}}
\L{\LB{}\Tab{8}{\}}}
\index{saveNodes}\Proc{saveNodes}\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{saveNodes}()_\{}}
\L{\LB{}\Tab{12}{\C{}/*_Save_the_node_list_to_corresponding_map_data_file_*/\CE{}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\C{}/*try_\{}}
\L{\LB{}\Tab{16}{XMLEncoder_e_=_new_XMLEncoder(new_BufferedOutputStream(}}
\L{\LB{}\Tab{20}{new_FileOutputStream(\3/tmp/dat\_\3+this.map+\3.xml\3)));}}
\L{\LB{}\Tab{16}{e.writeObject(this.nodes);_e.close();}}
\L{\LB{}\Tab{12}{\}_catch_(Exception_er)_\{}}
\L{\LB{}\Tab{16}{System.out.println(er);}}
\L{\LB{}\Tab{12}{\}*/\CE{}}}
\L{\LB{}\Tab{12}{\K{try}_\{}}
\L{\LB{}\Tab{16}{\V{FileOutputStream}_\V{out}_=_\K{new}_\V{FileOutputStream}(\V{dataDir}_+_\S{}\3/map\_\3\SE{}+\V{map}+\S{}\3.dat\3\SE{});}}
\L{\LB{}\Tab{16}{\V{ObjectOutputStream}_\V{s}_=_\K{new}_\V{ObjectOutputStream}(\V{out});}}
\L{\LB{}\Tab{16}{\V{s}.\V{writeObject}(\V{String}.\V{valueOf}(\V{nodeId}));}}
\L{\LB{}\Tab{16}{\V{s}.\V{writeObject}(\V{String}.\V{valueOf}(\V{edgeId}));}}
\L{\LB{}\Tab{16}{\V{s}.\V{writeObject}(\V{nodes});}}
\L{\LB{}\Tab{16}{\V{s}.\V{flush}();}}
\L{\LB{}\Tab{16}{\V{out}.\V{close}();}}
\L{\LB{}\Tab{12}{\}_\K{catch}_(\V{Exception}_\V{e})_\{}}
\L{\LB{}\Tab{16}{\V{Errors}.\V{debug}(\V{e});}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\index{SuppressWarnings}\Proc{SuppressWarnings}\L{\LB{}\Tab{8}{@\V{SuppressWarnings}(\S{}\3unchecked\3\SE{})}\Tab{44}{\C{}//_need_this_to_avoid_readObject_type_warning_which_can{'}t_be_fixed\CE{}}}
\L{\LB{}\Tab{8}{\K{public}_\K{void}_\V{loadNodes}()_\{}}
\L{\LB{}\Tab{12}{\C{}/*_Load_the_node_list_from_corresponding_map_data_file_*/\CE{}}}
\L{\LB{}\Tab{12}{\K{try}_\{}}
\L{\LB{}\Tab{16}{\V{FileInputStream}_\V{in}_=_\K{new}_\V{FileInputStream}(\V{dataDir}_+_\S{}\3/map\_\3\SE{}+\V{map}+\S{}\3.dat\3\SE{});}}
\L{\LB{}\Tab{16}{\V{ObjectInputStream}_\V{s}_=_\K{new}_\V{ObjectInputStream}(\V{in});}}
\L{\LB{}\Tab{16}{\V{nodeId}=_\V{Integer}.\V{parseInt}((\V{String})\V{s}.\V{readObject}());}}
\L{\LB{}\Tab{16}{\V{edgeId}=_\V{Integer}.\V{parseInt}((\V{String})\V{s}.\V{readObject}());}}
\L{\LB{}\Tab{16}{\V{nodes}_=_(\V{LinkedList}\<\V{NodeItem}\>)\V{s}.\V{readObject}();}}
\L{\LB{}\Tab{12}{\}_\K{catch}_(\V{Exception}_\V{e})_\{}}
\L{\LB{}\Tab{16}{\V{Errors}.\V{debug}(\V{e});}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{\}}}
